﻿using System.Windows;
using System.Windows.Controls;

namespace FluentTemplates.Test.AttributeControls
{
    [TemplatePart(Name = ElementNames.NameBox, Type = typeof (TextBox))]
    [TemplatePart(Name = ElementNames.SubmitButton, Type = typeof (Button))]
    public class AttributeTestControl : Control, ITemplatePartBinding
    {
        #region Fields

        [TemplatePartBinding(Name = ElementNames.NameBox, Required = true)] 
        internal TextBox _nameBox;

        [TemplatePartBinding(Name = ElementNames.SubmitButton, Required = true)] 
        internal Button _submitButton;

        #endregion

        #region C'tors

        public AttributeTestControl()
        {
            DefaultStyleKey = typeof (AttributeTestControl);
        }

        #endregion

        #region Instance Methods

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (DesignTools.IsInDesignModeStatic)
                return;

            TemplatePartBinding.BindTemplateParts(this);
        }

        #endregion

        #region ITemplatePartBinding Members

        public object GetTemplatePartBinding(string partName)
        {
            return GetTemplateChild(partName);
        }

        #endregion

        #region Nested type: ElementNames

        private static class ElementNames
        {
            #region Constants

            public const string NameBox = "NameBox";
            public const string SubmitButton = "SubmitButton";

            #endregion
        }

        #endregion
    }
}